/* This DOS utility takes two binary files and joins them together to make *
 * one bigger file. This was written so that several binary ROM images     *
 * could be combined into one big binary image and then split into Intel   *
 * Hex pages for loading onto the ZAX.										*
 *						written by Paul Hutchinson							*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "dos.h"


FILE	*InFile1, *InFile2, *OutFile;  /* input & output files */

int ch1,ch2;



void Join(void)
{
unsigned char  end;
	end=0;
	while (!end)
		{
		if	((ch1 = getc(InFile1)) == EOF)
			end=1;
		else
			putc(ch1,OutFile);
		}
	end=0;
	while (!end)
		{
		if	((ch2 = getc(InFile2)) == EOF)
			end=1;
		else
			putc(ch2,OutFile);
		}
}

int main(int argc, char *argv[])
{
	if (argc != 4)
	{
		printf("JOINBIN: JOINBIN file1 file2 joinedfile\n");
		return EXIT_FAILURE;
	}
	if ((InFile1 = fopen(argv[1], "rb")) == NULL)
	{
		fprintf(stderr, "JOINBIN: Unable to open file: %s\n", argv[1]);
		return EXIT_FAILURE;
	}

	if ((InFile2 = fopen(argv[2], "rb")) == NULL)
	{
		fprintf(stderr, "JOINBIN: Unable to open file: %s\n", argv[2]);
		return EXIT_FAILURE;
	}

	if ((OutFile = fopen(argv[3], "wb")) == NULL)
	{
		fprintf(stderr, "JOINBIN: Unable to create file: %s\n", argv[3]);
		return EXIT_FAILURE;
	}

	Join();

	fclose(InFile1);
	fclose(InFile2);
	fclose(OutFile);

	return EXIT_SUCCESS;
}





